package com.es.gateway.一砂云.活体检测的_全平台;
import com.es.gateway.sdk.ESGateway;
import com.es.gateway.sdk.app.livingdetect.*;
import com.es.gateway.sdk.constant.AlgorithmE;
import com.es.gateway.sdk.entity.GatewayResponse;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * 活体检测全平台，参考文档：https://esandinfo.yuque.com/yv6e1k/aa4qsg/axsfon
 */
@Slf4j
public class LivingdetectTester {
    /**
     * 获取TOKEN，参考文档：https://esandinfo.yuque.com/yv6e1k/aa4qsg/chz53t
     */
    @Test
    public void LivingdetectRequestTest(){
        String appCode = "d2808c1338ce01f3e3efdb486f9effb9";
        AlgorithmE algo = AlgorithmE.MD5;
        String key = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhdQdw6uTGz+X4e+/eGpu4dcKrfrjQAe0tTQyn6TuKBobcsUsESkx9jcCeG4cpuxmN8jNeDAZsbTujNLD/aYl2g==";
        ESGateway esGateway = new ESGateway(appCode, algo, key);

        LivingdetectRequest livingdetectRequest = new LivingdetectRequest();
        livingdetectRequest.setinitMsg("@Android,2,8,1658484566@NibhdDZK9ja0gwaTLRo5KpckYi6y6tRCjWFqAMZZzNNeLSsfNtVddN8/dzI6HJFUp+tg1c0Qc1DqpP/CDriJlOKEgcGvlXLUP3fhv2wYGwT0SDRAv1x2obTbWn6N0AVhHkUApE1GjEZlSVHPQn350vSUa8a/Hm4RBW7D0Uu8BjcR6FS8Q/7j2klpH0lRTmsZI7oxUA2qAfX7pZ7e068ZR613bdSzwbkSvaer7sSqmJnMwvp0f3oRZ5ZC0NrUuK2WPkETzzklCbUhE24yB1e3xN11HG52HX+/MfyHuzPGoLGNd4VfPzfaul+m6hfl3Aaoy8VE9tjk7ewdaM8TtsDN4BMvcAJ75CKjfxCdkXOqdq2XVXtmMnGNjse0DpZfzhFko3G1HtOCPliU+b5ytIB0DNi/aA2ec0Ojgqu0JUjkilxq52jIns05Cj6eDJ+MeOWc1pauxmBH8qkKLPK7VCQxpYRn8PphMLcv6+w6Nc92rEjXGN4gL6bndjrnMEpPeK/eUf+Oq9TfYQ7YyBWOIPse8GJTNcZocxR3j8KRHeO70j0dDme+DJqDblcz2yU2AzgV1Gm6VR8rDw3fN1KkMVgc9w==");
        GatewayResponse gatewayResponse = esGateway.sendToGateWay(LivingdetectRequest.act,livingdetectRequest.toJsonStr());
        log.info("服务器端返回: {}", gatewayResponse.toJsonStr());
        if (gatewayResponse.getBizContent() != null) {
            log.info("验签结果: {}", gatewayResponse.isSignVerifyResult());
            LivingdetectResponse response = LivingdetectResponse.fromJsonStr(gatewayResponse.getBizContent());
            log.info("业务数据为: {}", response.toJsonStr());
        }
    }
    /**
     * 获取测试结果，参考文档：https://esandinfo.yuque.com/yv6e1k/aa4qsg/rp6dws
     */
    @Test
    public void LivingdetectRequestVerifyRequestTest(){
        String appCode = "d2808c1338ce01f3e3efdb486f9effb9";
        AlgorithmE algo = AlgorithmE.MD5;
        String key = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhdQdw6uTGz+X4e+/eGpu4dcKrfrjQAe0tTQyn6TuKBobcsUsESkx9jcCeG4cpuxmN8jNeDAZsbTujNLD/aYl2g==";
        ESGateway esGateway = new ESGateway(appCode,algo,key);

        LivingdetectVerifyRequest livingdetectVerifyRequest = new LivingdetectVerifyRequest();
        livingdetectVerifyRequest.setToken("kbi+dIKhrfdn177jS3yYw9Rv+GfkJXNbIRpJUbqSXRbqbw+HtkFAv4JT9doMBWZXkaQLxBc44BedMtKJs/d76XARaVHwzvjoX/uVbiOqBJ4=");
        livingdetectVerifyRequest.setVerifyMsg("NULL");
        GatewayResponse gatewayResponse = esGateway.sendToGateWay(LivingdetectVerifyRequest.act, livingdetectVerifyRequest.toJsonStr());
        log.info("服务器端返回：{}",gatewayResponse.toJsonStr());
        if(gatewayResponse.getBizContent() != null){
            log.info("验签结果：{}",gatewayResponse.isSignVerifyResult());
            LivingdetectVerifyResponse response = LivingdetectVerifyResponse.fromJsonStr(gatewayResponse.getBizContent());
            log.info("业务数据：{}",response.toJsonStr());

        }
    }
}
